<?php

declare(strict_types=1);

namespace App\CustHub\Mapper;

use App\CustHub\Model\ChTagPreset;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Collection;
use Mine\Abstracts\AbstractMapper;

class ChTagPresetMapper extends AbstractMapper
{
    public function assignModel()
    {
        $this->model = ChTagPreset::class;
    }

    public function getTagList(): array|Collection|\Hyperf\Collection\Collection
    {
        return $this->model::query()
            ->select(['id','name','group_id','parent_id','sort','sub_type','duration','unit','remark'])
            ->orderBy('id')
            ->get();
    }

    /**
     * 搜索处理器.
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        if (isset($params['parent_id']) && filled($params['parent_id'])) {
            $query->where('parent_id', $params['parent_id']);
        }

        return $query;
    }
}